var n=0;
var p=0;
$(document).ready(getQuestionsInfo());
function addPage() {
    var sumpage=parseInt($("#a-sum").html());
    n=parseInt(n);
    if (sumpage==n+1){
        return;
    }
    n++;
    getQuestionsInfo()
}
function devPage() {
    n=parseInt(n);
    if (n<=0){
        return;
    }
    n--;
    getQuestionsInfo();
}

function gohead() {
    n=parseInt(n);
    if (n==0){
        return;
    }
    $("#a-jump").val("");
    n=0;
    getQuestionsInfo();
}
function jumpPage() {

    n=parseInt($("#a-jump").val())-1;
    getQuestionsInfo()
}

function getQuestionsInfo() {
    sumpage=getsumpage();
    var scopeid=$("#choose-scope").val();
    var typeid=$("#choose-type").val();
    var content=$("#input-seach").val();
    for (var i=0;i<$(".tbody-tr").length;i++){
        $(".tbody-tr").eq(i).hide();
    }
    n=parseInt(n);
    $("#a-index").html(n+1);


    $.ajax({
        url: "getQuestion.action",
        type: "post",
        async: "true",
        dataType: "json",
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: {
            "scopeid":scopeid,
            "typeid":typeid,
            "content":content,
            "n":n
        },
        success: function (data) {
            var type=["选择题","是非题"];
            var scope=["消费性","经营性","按揭性"];
            var index=["A","B","C","D"];
           for (var i=0;i<data.questionslist.length;i++){

               $(".tbody-tr").eq(i).show();
               $(".td-id").eq(i).html(data.questionslist[i].id)
               $(".td-content").eq(i).html(data.questionslist[i].content)
               $(".td-type").eq(i).html(type[data.questionslist[i].kindId-1])
               $(".td-scope").eq(i).html(scope[data.questionslist[i].scopeId-1])
               var answer=data.questionslist[i].answer.split(";");
               var a=data.questionslist[i].a;
               var b=data.questionslist[i].b;
               var c=data.questionslist[i].c;
               var d=data.questionslist[i].d;
               var rate=[a,b,c,d];
               $(".select-answer").eq(i).html("");
                for (var j=0;j<answer.length+1;j++){
                    if (j==0) {
                        $(".select-answer").eq(i).append("<option value='" + j + "'>" + '点击查看' + "</option>")
                    }
                    else {
                        $(".select-answer").eq(i).append("<option value='" + j + "' disabled='true'>" +index[j-1]+'.'+answer[j-1]+':'+rate[j-1]+'分'+ "</option>")
                    }
                }

           }
        },
        error: function () {
            alert("请求错误");
        }
    })
}
    function getsumpage() {

        var scopeid=$("#choose-scope").val();
        var typeid=$("#choose-type").val();
        var content=$("#input-seach").val();
        $.ajax({
            url: "getsumpage.action",
            type: "post",
            async: "true",
            dataType: "json",
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            data: {
                "scopeid":scopeid,
                "typeid":typeid,
                "content":content,
            },
            success: function (data) {
                $("#a-sum").html(data.sumpage);

                if (p==0){
                    for (var i=1;i<data.sumpage+1;i++){

                        $("#a-jump").append("<option value='"+i+"'>"+i+"</option>")
                    }
                    p++;
                }

            },
            error: function () {
                alert("请求错误");
            }
        })
        return n;
    }


